/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.shop.web.product;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.shop.entity.product.HkShopProductImages;
import com.thinkgem.jeesite.modules.hk.shop.service.product.HkShopProductImagesService;

/**
 * 乐购产品图片Controller
 * @author 罗天文
 * @version 2018-05-15
 */
@Controller
@RequestMapping(value = "${adminPath}/shop/product/hkShopProductImages")
public class HkShopProductImagesController extends BaseController {

	@Autowired
	private HkShopProductImagesService hkShopProductImagesService;
	
	@ModelAttribute
	public HkShopProductImages get(@RequestParam(required=false) String id) {
		HkShopProductImages entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkShopProductImagesService.get(id);
		}
		if (entity == null){
			entity = new HkShopProductImages();
		}
		return entity;
	}
	
	@RequiresPermissions("shop:product:hkShopProductImages:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkShopProductImages hkShopProductImages, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkShopProductImages> page = hkShopProductImagesService.findPage(new Page<HkShopProductImages>(request, response), hkShopProductImages); 
		model.addAttribute("page", page);
		return "hk/shop/product/hkShopProductImagesList";
	}

	@RequiresPermissions("shop:product:hkShopProductImages:view")
	@RequestMapping(value = "form")
	public String form(HkShopProductImages hkShopProductImages, Model model) {
		model.addAttribute("hkShopProductImages", hkShopProductImages);
		return "hk/shop/product/hkShopProductImagesForm";
	}

	@RequiresPermissions("shop:product:hkShopProductImages:edit")
	@RequestMapping(value = "save")
	public String save(HkShopProductImages hkShopProductImages, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkShopProductImages)){
			return form(hkShopProductImages, model);
		}
		hkShopProductImagesService.save(hkShopProductImages);
		addMessage(redirectAttributes, "保存乐购产品图片成功");
		return "redirect:"+Global.getAdminPath()+"/shop/product/hkShopProductImages/?repage";
	}
	
	@RequiresPermissions("shop:product:hkShopProductImages:edit")
	@RequestMapping(value = "delete")
	public String delete(HkShopProductImages hkShopProductImages, RedirectAttributes redirectAttributes) {
		hkShopProductImagesService.delete(hkShopProductImages);
		addMessage(redirectAttributes, "删除乐购产品图片成功");
		return "redirect:"+Global.getAdminPath()+"/shop/product/hkShopProductImages/?repage";
	}

}